package diplom

class MyTagsTagLib {
    def goodGrowth = { attrs ->
        def changed = attrs.changed
        def value = attrs.value
        def withPercent = attrs.withPercent == "true"
        if (changed instanceof Float) {
            changed = changed.round(1)
        }
        if (value instanceof Float || value instanceof Double) {
            value = value.round(1)
        }
        out << '<i><div class="value">'
        if (changed) {
            def color =  changed > 0 ? 'red' : 'green'
            out << "(<span style='color:$color'>$changed</span>)"
        }

        out << "${value}${withPercent ? '%' : ""} </div></i>"
    }

    def goodGrowth2 = { attrs ->
        def changed = attrs.changed
        def value = attrs.value
        def withPercent = attrs.withPercent == "true"
        if (changed instanceof Float) {
            changed = changed.round(1)
        }
        if (value instanceof Float || value instanceof Double) {
            value = value.round(1)
        }
        out << '<i><div class="value">'
        if (changed) {
            def color =  changed < 0 ? 'red' : 'green'
            out << "(<span style='color:$color'>$changed</span>)"
        }

        out << "${value}${withPercent ? '%' : ""} </div></i>"
    }
    def fileLink = { attrs, body ->
        def link = g.createLink(action: "fileOutput", params: [fileName: attrs.path])
        def style =  attrs.value > attrs.valueLimit ? 'warn' : attrs.index % 2 ? 'dark' : ''
        out << """
            <div onclick="openurl('$link')" class="$style">
                <div class="filesName">$attrs.name</div>
                ${body()}
                <br/>
            </div>
            """
    }

    def fileLink2 = { attrs, body ->
        def link = g.createLink(action: "fileOutput", params: [fileName: attrs.path])
        def style =  attrs.value < attrs.valueLimit ? 'warn' : attrs.index % 2 ? 'dark' : ''
        out << """
            <div onclick="openurl('$link')" class="$style">
                <div class="filesName">$attrs.name</div>
                ${body()}
                <br/>
            </div>
            """
    }
}

